

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
    <style>
    /* base */
    html,
    body,
    .container {
      width: 100%;
      height: 100%;
    }

    a,
    a:link,
    a:visited {
      text-decoration: none;
      color: inherit;
    }

    ul {
      list-style: none;
    }

    *,
    ::before,
    ::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    *:focus {
      outline: 0;
    }

    .container {
      display: flex;
      padding-top: 20px;
    }

    /* Nav */
    .container .doc-nav {
      position: fixed;
      height: 100%;
      margin: 0 30px 0 40px;
      width: 280px;
    }

    .doc-nav .nav-header {
      display: flex;
      align-items: center;
      box-sizing: border-box;
      background-color: rgb(240, 241, 242);
      height: 40px;
      padding: 16px;
      font-size: 18px;
      font-weight: 500;
      color: rgb(62, 64, 66);
      cursor: pointer;
    }

    .doc-nav .nav-content {
      height: calc(100% - 40px);
      overflow-y: auto;
      color: rgb(32, 34, 36);
    }

    .doc-nav .nav-content .nav-list,
    .doc-nav .nav-content .nav-sub-list {
      line-height: 1.5rem;
    }

    .doc-nav .nav-content .nav-label {
      display: inline-block;
      position: relative;
      padding: 2px 0 2px 20px;
      margin-bottom: 4px;
    }

    .doc-nav .nav-content .nav-sub-label {
      position: relative;
      padding: 2px 0 2px 40px;
      font-size: 14px;
    }

    .doc-nav .nav-content .nav-sub-label:hover {
      text-decoration: underline;
    }

    .doc-nav .nav-content .nav-list .nav-label.group::before {
      border-bottom: 0.25rem solid transparent;
      border-left: 0.25rem solid #6e7072;
      border-right: 0;
      border-top: 0.25rem solid transparent;
      content: '';
      display: block;
      height: 0;
      left: 0.5rem;
      position: absolute;
      top: 0.625rem;
      transition: transform 0.1s linear;
      width: 0;
    }

    .doc-nav .nav-content .nav-list .nav-label.group.active::before {
      transform: rotate(90deg);
    }

    /* doc content */
    .container .doc-content {
      position: fixed;
      height: 100%;
      width: calc(100% - 80px - 40px - 30px - 240px);
      right: 0%;
      overflow-y: auto;
    }

    .doc-title {
      border-bottom: 1px solid #dcdee0;
      font-size: 22px;
      margin: 8px 0 0;
      padding-bottom: 16px;
    }

    .doc-content h3 {
      font-size: 24px;
      font-weight: 600;
      margin: 24px 0;
    }

    .doc-content h4 {
      font-size: 22px;
      font-weight: 500;
      margin: 30px 0 8px;
    }

    .doc-content h4 span {
      color: #007d9c;
    }

    .doc-content .doc-declare {
      background-color: #fafafa;
      border-radius: 5px;
      border: 1px solid #ccc;
      font-size: 14px;
      overflow-x: auto;
      padding: 10px;
      tab-size: 4;
      line-height: 20px;
    }

    .doc-content .doc-comment {
      font-size: 16px;
      margin: 16px 0;
      line-height: 24px;
      word-break: break-word;
    }
  </style>

</head>
<body>
  <div class="container">
    <div class="doc-nav">
      <a href="#Documentation" class="nav-header">Documentation</a>
      <nav class="nav-content">
        <ul class="nav-list">
          <li>
            <a href="#includes" class="nav-label">Includes</a>
             
            <ul class="nav-sub-list">

              <li>
                <a href="#coap_session.h" class="nav-sub-label">coap_session.h</a>
              </li>
      

              <li>
                <a href="#pdu.h" class="nav-sub-label">pdu.h</a>
              </li>
      
            </ul>
            
          </li>
          <li>
            <a href="#macros" class="nav-label">Macros</a>
             
            <ul class="nav-sub-list">

              <li>
                <a href="#COAP_DTLS_H_" class="nav-sub-label">COAP_DTLS_H_</a>
              </li>
      

              <li>
                <a href="#COAP_TLS_LIBRARY_NOTLS" class="nav-sub-label">COAP_TLS_LIBRARY_NOTLS</a>
              </li>
      

              <li>
                <a href="#COAP_TLS_LIBRARY_TINYDTLS" class="nav-sub-label">COAP_TLS_LIBRARY_TINYDTLS</a>
              </li>
      

              <li>
                <a href="#COAP_TLS_LIBRARY_OPENSSL" class="nav-sub-label">COAP_TLS_LIBRARY_OPENSSL</a>
              </li>
      

              <li>
                <a href="#COAP_TLS_LIBRARY_GNUTLS" class="nav-sub-label">COAP_TLS_LIBRARY_GNUTLS</a>
              </li>
      

              <li>
                <a href="#COAP_DTLS_PKI_SETUP_VERSION" class="nav-sub-label">COAP_DTLS_PKI_SETUP_VERSION</a>
              </li>
      
            </ul>
            
          </li>
          <li>
            <a href="#functions" class="nav-label">Functions</a>
             
            <ul class="nav-sub-list">

              <li>
                <a href="#coap_dtls_is_supported" class="nav-sub-label">coap_dtls_is_supported</a>
              </li>
      

              <li>
                <a href="#coap_tls_is_supported" class="nav-sub-label">coap_tls_is_supported</a>
              </li>
      

              <li>
                <a href="#coap_dtls_new_context" class="nav-sub-label">coap_dtls_new_context</a>
              </li>
      

              <li>
                <a href="#coap_dtls_context_set_psk" class="nav-sub-label">coap_dtls_context_set_psk</a>
              </li>
      

              <li>
                <a href="#coap_dtls_context_set_pki" class="nav-sub-label">coap_dtls_context_set_pki</a>
              </li>
      

              <li>
                <a href="#coap_dtls_context_set_pki_root_cas" class="nav-sub-label">coap_dtls_context_set_pki_root_cas</a>
              </li>
      

              <li>
                <a href="#coap_dtls_context_check_keys_enabled" class="nav-sub-label">coap_dtls_context_check_keys_enabled</a>
              </li>
      

              <li>
                <a href="#coap_dtls_free_context" class="nav-sub-label">coap_dtls_free_context</a>
              </li>
      

              <li>
                <a href="#coap_dtls_new_client_session" class="nav-sub-label">coap_dtls_new_client_session</a>
              </li>
      

              <li>
                <a href="#coap_dtls_new_server_session" class="nav-sub-label">coap_dtls_new_server_session</a>
              </li>
      

              <li>
                <a href="#coap_dtls_free_session" class="nav-sub-label">coap_dtls_free_session</a>
              </li>
      

              <li>
                <a href="#coap_dtls_session_update_mtu" class="nav-sub-label">coap_dtls_session_update_mtu</a>
              </li>
      

              <li>
                <a href="#coap_dtls_send" class="nav-sub-label">coap_dtls_send</a>
              </li>
      

              <li>
                <a href="#coap_dtls_is_context_timeout" class="nav-sub-label">coap_dtls_is_context_timeout</a>
              </li>
      

              <li>
                <a href="#coap_dtls_get_context_timeout" class="nav-sub-label">coap_dtls_get_context_timeout</a>
              </li>
      

              <li>
                <a href="#coap_dtls_get_timeout" class="nav-sub-label">coap_dtls_get_timeout</a>
              </li>
      

              <li>
                <a href="#coap_dtls_handle_timeout" class="nav-sub-label">coap_dtls_handle_timeout</a>
              </li>
      

              <li>
                <a href="#coap_dtls_receive" class="nav-sub-label">coap_dtls_receive</a>
              </li>
      

              <li>
                <a href="#coap_dtls_hello" class="nav-sub-label">coap_dtls_hello</a>
              </li>
      

              <li>
                <a href="#coap_dtls_get_overhead" class="nav-sub-label">coap_dtls_get_overhead</a>
              </li>
      

              <li>
                <a href="#coap_tls_new_client_session" class="nav-sub-label">coap_tls_new_client_session</a>
              </li>
      

              <li>
                <a href="#coap_tls_new_server_session" class="nav-sub-label">coap_tls_new_server_session</a>
              </li>
      

              <li>
                <a href="#coap_tls_free_session" class="nav-sub-label">coap_tls_free_session</a>
              </li>
      

              <li>
                <a href="#coap_tls_write" class="nav-sub-label">coap_tls_write</a>
              </li>
      

              <li>
                <a href="#coap_tls_read" class="nav-sub-label">coap_tls_read</a>
              </li>
      

              <li>
                <a href="#coap_dtls_startup" class="nav-sub-label">coap_dtls_startup</a>
              </li>
      

              <li>
                <a href="#coap_dtls_set_log_level" class="nav-sub-label">coap_dtls_set_log_level</a>
              </li>
      

              <li>
                <a href="#coap_dtls_get_log_level" class="nav-sub-label">coap_dtls_get_log_level</a>
              </li>
      
            </ul>
            
          </li>
          <li>
            <a href="#vars" class="nav-label">Vars</a>
             
            <ul class="nav-sub-list">

              <li>
                <a href="#coap_tls_version_t" class="nav-sub-label">coap_tls_version_t</a>
              </li>
      

              <li>
                <a href="#coap_dtls_pki_t" class="nav-sub-label">coap_dtls_pki_t</a>
              </li>
      
            </ul>
            
          </li>
          <li>
            <a href="#consts" class="nav-label">Consts</a>
            
            <ul class="nav-sub-list">
            
            </ul>
            
          </li>
          <li>
            <a href="#types" class="nav-label">Types</a>
            
            <ul class="nav-sub-list">
            
            </ul>
            
          </li>
          <li>
            <a href="#typedefs" class="nav-label">Typedefs</a>
             
            <ul class="nav-sub-list">

              <li>
                <a href="#coap_tls_version_t;
" class="nav-sub-label">coap_tls_version_t;
</a>
              </li>
      

              <li>
                <a href="#coap_dtls_security_setup_t" class="nav-sub-label">coap_dtls_security_setup_t</a>
              </li>
      

              <li>
                <a href="#coap_dtls_cn_callback_t" class="nav-sub-label">coap_dtls_cn_callback_t</a>
              </li>
      

              <li>
                <a href="#coap_asn1_privatekey_type_t;
" class="nav-sub-label">coap_asn1_privatekey_type_t;
</a>
              </li>
      

              <li>
                <a href="#coap_pki_key_t;
" class="nav-sub-label">coap_pki_key_t;
</a>
              </li>
      

              <li>
                <a href="#coap_pki_key_pem_t;
" class="nav-sub-label">coap_pki_key_pem_t;
</a>
              </li>
      

              <li>
                <a href="#coap_pki_key_asn1_t;
" class="nav-sub-label">coap_pki_key_asn1_t;
</a>
              </li>
      

              <li>
                <a href="#key;
" class="nav-sub-label">key;
</a>
              </li>
      

              <li>
                <a href="#coap_dtls_key_t" class="nav-sub-label">coap_dtls_key_t</a>
              </li>
      

              <li>
                <a href="#coap_dtls_pki_t;
" class="nav-sub-label">coap_dtls_pki_t;
</a>
              </li>
      

              <li>
                <a href="#coap_dtls_role_t;
" class="nav-sub-label">coap_dtls_role_t;
</a>
              </li>
      
            </ul>
            
          </li>
        </ul>
      </nav>
    </div>
    <div class="doc-content">
      <h2 id="Documentation" class="doc-title">Documentation</h2>
      <h3 id="includes">Includes</h3>
      

      <h4 id="coap_session.h"><span>coap_session.h</span></h4>
      <pre class="doc-declare"><code>#include "coap_session.h"
</code></pre>
      <pre class="doc-comment">#include "coap_session.h"
</pre>

      <h4 id="pdu.h"><span>pdu.h</span></h4>
      <pre class="doc-declare"><code>#include "pdu.h"
</code></pre>
      <pre class="doc-comment">#include "pdu.h"
</pre>
      <h3 id="macros">Macros</h3>
      

      <h4 id="COAP_DTLS_H_">Marco <span>COAP_DTLS_H_</span></h4>
      <pre class="doc-declare"><code>#define COAP_DTLS_H_
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="COAP_TLS_LIBRARY_NOTLS">Marco <span>COAP_TLS_LIBRARY_NOTLS</span></h4>
      <pre class="doc-declare"><code>#define COAP_TLS_LIBRARY_NOTLS 0 /**< No DTLS library */
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="COAP_TLS_LIBRARY_TINYDTLS">Marco <span>COAP_TLS_LIBRARY_TINYDTLS</span></h4>
      <pre class="doc-declare"><code>#define COAP_TLS_LIBRARY_TINYDTLS 1 /**< Using TinyDTLS library */
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="COAP_TLS_LIBRARY_OPENSSL">Marco <span>COAP_TLS_LIBRARY_OPENSSL</span></h4>
      <pre class="doc-declare"><code>#define COAP_TLS_LIBRARY_OPENSSL 2 /**< Using OpenSSL library */
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="COAP_TLS_LIBRARY_GNUTLS">Marco <span>COAP_TLS_LIBRARY_GNUTLS</span></h4>
      <pre class="doc-declare"><code>#define COAP_TLS_LIBRARY_GNUTLS 3 /**< Using GnuTLS library */
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="COAP_DTLS_PKI_SETUP_VERSION">Marco <span>COAP_DTLS_PKI_SETUP_VERSION</span></h4>
      <pre class="doc-declare"><code>#define COAP_DTLS_PKI_SETUP_VERSION 1 /**< Latest PKI setup version */
</code></pre>
      <pre class="doc-comment"></pre>
      <h3 id="functions">Functions</h3>
      

      <h4 id="coap_dtls_is_supported">Func <span>coap_dtls_is_supported</span></h4>
      <pre class="doc-declare"><code>int coap_dtls_is_supported(void);</code></pre>
      <pre class="doc-comment">/**
 * Check whether DTLS is available.
 *
 * @return @c 1 if support for DTLS is enabled, or @c 0 otherwise.
 */</pre>

      <h4 id="coap_tls_is_supported">Func <span>coap_tls_is_supported</span></h4>
      <pre class="doc-declare"><code>int coap_tls_is_supported(void);</code></pre>
      <pre class="doc-comment">/**
 * Check whether TLS is available.
 *
 * @return @c 1 if support for TLS is enabled, or @c 0 otherwise.
 */</pre>

      <h4 id="coap_dtls_new_context">Func <span>coap_dtls_new_context</span></h4>
      <pre class="doc-declare"><code>void *
coap_dtls_new_context(struct coap_context_t *coap_context);</code></pre>
      <pre class="doc-comment">/**
 * Creates a new DTLS context for the given @p coap_context. This function
 * returns a pointer to a new DTLS context object or @c NULL on error.
 *
 * Internal function.
 *
 * @param coap_context The CoAP context where the DTLS object shall be used.
 *
 * @return A DTLS context object or @c NULL on error.
 */</pre>

      <h4 id="coap_dtls_context_set_psk">Func <span>coap_dtls_context_set_psk</span></h4>
      <pre class="doc-declare"><code>int
coap_dtls_context_set_psk(struct coap_context_t *coap_context,
                         const char *identity_hint,
                         coap_dtls_role_t role);</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="coap_dtls_context_set_pki">Func <span>coap_dtls_context_set_pki</span></h4>
      <pre class="doc-declare"><code>int
coap_dtls_context_set_pki(struct coap_context_t *coap_context,
                         coap_dtls_pki_t *setup_data,
                         coap_dtls_role_t role);</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="coap_dtls_context_set_pki_root_cas">Func <span>coap_dtls_context_set_pki_root_cas</span></h4>
      <pre class="doc-declare"><code>int
coap_dtls_context_set_pki_root_cas(struct coap_context_t *coap_context,
                                  const char *ca_file,
                                  const char *ca_dir);</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="coap_dtls_context_check_keys_enabled">Func <span>coap_dtls_context_check_keys_enabled</span></h4>
      <pre class="doc-declare"><code>int coap_dtls_context_check_keys_enabled(struct coap_context_t *coap_context);</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="coap_dtls_free_context">Func <span>coap_dtls_free_context</span></h4>
      <pre class="doc-declare"><code>void coap_dtls_free_context(void *dtls_context);</code></pre>
      <pre class="doc-comment">/**
 * Releases the storage allocated for @p dtls_context.
 *
 * Internal function.
 *
 * @param dtls_context The DTLS context as returned by coap_dtls_new_context().
 */</pre>

      <h4 id="coap_dtls_new_client_session">Func <span>coap_dtls_new_client_session</span></h4>
      <pre class="doc-declare"><code>void *coap_dtls_new_client_session(coap_session_t *coap_session);</code></pre>
      <pre class="doc-comment">/**
 * Create a new client-side session. This should send a HELLO to the server.
 *
 * Internal function.
 *
 * @param coap_session   The CoAP session.
 *
 * @return Opaque handle to underlying TLS library object containing security
 *         parameters for the session.
*/</pre>

      <h4 id="coap_dtls_new_server_session">Func <span>coap_dtls_new_server_session</span></h4>
      <pre class="doc-declare"><code>void *coap_dtls_new_server_session(coap_session_t *coap_session);</code></pre>
      <pre class="doc-comment">/**
 * Create a new DTLS server-side session.
 * Called after coap_dtls_hello() has returned @c 1, signalling that a validated
 * HELLO was received from a client.
 * This should send a HELLO to the server.
 *
 * Internal function.
 *
 * @param coap_session   The CoAP session.
 *
 * @return Opaque handle to underlying TLS library object containing security
 *         parameters for the DTLS session.
 */</pre>

      <h4 id="coap_dtls_free_session">Func <span>coap_dtls_free_session</span></h4>
      <pre class="doc-declare"><code>void coap_dtls_free_session(coap_session_t *coap_session);</code></pre>
      <pre class="doc-comment">/**
 * Terminates the DTLS session (may send an ALERT if necessary) then frees the
 * underlying TLS library object containing security parameters for the session.
 *
 * Internal function.
 *
 * @param coap_session   The CoAP session.
 */</pre>

      <h4 id="coap_dtls_session_update_mtu">Func <span>coap_dtls_session_update_mtu</span></h4>
      <pre class="doc-declare"><code>void coap_dtls_session_update_mtu(coap_session_t *coap_session);</code></pre>
      <pre class="doc-comment">/**
 * Notify of a change in the CoAP session's MTU, for example after
 * a PMTU update.
 *
 * Internal function.
 *
 * @param coap_session   The CoAP session.
 */</pre>

      <h4 id="coap_dtls_send">Func <span>coap_dtls_send</span></h4>
      <pre class="doc-declare"><code>int coap_dtls_send(coap_session_t *coap_session,
                  const uint8_t *data,
                  size_t data_len);</code></pre>
      <pre class="doc-comment">/**
 * Send data to a DTLS peer.
 *
 * Internal function.
 *
 * @param coap_session The CoAP session.
 * @param data      pointer to data.
 * @param data_len  Number of bytes to send.
 *
 * @return @c 0 if this would be blocking, @c -1 if there is an error or the
 *         number of cleartext bytes sent.
 */</pre>

      <h4 id="coap_dtls_is_context_timeout">Func <span>coap_dtls_is_context_timeout</span></h4>
      <pre class="doc-declare"><code>int coap_dtls_is_context_timeout(void);</code></pre>
      <pre class="doc-comment">/**
 * Check if timeout is handled per CoAP session or per CoAP context.
 *
 * Internal function.
 *
 * @return @c 1 of timeout and retransmit is per context, @c 0 if it is
 *         per session.
 */</pre>

      <h4 id="coap_dtls_get_context_timeout">Func <span>coap_dtls_get_context_timeout</span></h4>
      <pre class="doc-declare"><code>coap_tick_t coap_dtls_get_context_timeout(void *dtls_context);</code></pre>
      <pre class="doc-comment">/**
 * Do all pending retransmits and get next timeout
 *
 * Internal function.
 *
 * @param dtls_context The DTLS context.
 *
 * @return @c 0 if no event is pending or date of the next retransmit.
 */</pre>

      <h4 id="coap_dtls_get_timeout">Func <span>coap_dtls_get_timeout</span></h4>
      <pre class="doc-declare"><code>coap_tick_t coap_dtls_get_timeout(coap_session_t *coap_session);</code></pre>
      <pre class="doc-comment">/**
 * Get next timeout for this session.
 *
 * Internal function.
 *
 * @param coap_session The CoAP session.
 *
 * @return @c 0 If no event is pending or date of the next retransmit.
 */</pre>

      <h4 id="coap_dtls_handle_timeout">Func <span>coap_dtls_handle_timeout</span></h4>
      <pre class="doc-declare"><code>void coap_dtls_handle_timeout(coap_session_t *coap_session);</code></pre>
      <pre class="doc-comment">/**
 * Handle a DTLS timeout expiration.
 *
 * Internal function.
 *
 * @param coap_session The CoAP session.
 */</pre>

      <h4 id="coap_dtls_receive">Func <span>coap_dtls_receive</span></h4>
      <pre class="doc-declare"><code>int coap_dtls_receive(coap_session_t *coap_session,
                     const uint8_t *data,
                     size_t data_len);</code></pre>
      <pre class="doc-comment">/**
 * Handling incoming data from a DTLS peer.
 *
 * Internal function.
 *
 * @param coap_session The CoAP session.
 * @param data      Encrypted datagram.
 * @param data_len  Encrypted datagram size.
 *
 * @return Result of coap_handle_dgram on the decrypted CoAP PDU
 *         or @c -1 for error.
 */</pre>

      <h4 id="coap_dtls_hello">Func <span>coap_dtls_hello</span></h4>
      <pre class="doc-declare"><code>int coap_dtls_hello(coap_session_t *coap_session,
                   const uint8_t *data,
                   size_t data_len);</code></pre>
      <pre class="doc-comment">/**
 * Handling client HELLO messages from a new candiate peer.
 * Note that session->tls is empty.
 *
 * Internal function.
 *
 * @param coap_session The CoAP session.
 * @param data      Encrypted datagram.
 * @param data_len  Encrypted datagram size.
 *
 * @return @c 0 if a cookie verification message has been sent, @c 1 if the
 *        HELLO contains a valid cookie and a server session should be created,
 *        @c -1 if the message is invalid.
 */</pre>

      <h4 id="coap_dtls_get_overhead">Func <span>coap_dtls_get_overhead</span></h4>
      <pre class="doc-declare"><code>unsigned int coap_dtls_get_overhead(coap_session_t *coap_session);</code></pre>
      <pre class="doc-comment">/**
 * Get DTLS overhead over cleartext PDUs.
 *
 * Internal function.
 *
 * @param coap_session The CoAP session.
 *
 * @return Maximum number of bytes added by DTLS layer.
 */</pre>

      <h4 id="coap_tls_new_client_session">Func <span>coap_tls_new_client_session</span></h4>
      <pre class="doc-declare"><code>void *coap_tls_new_client_session(coap_session_t *coap_session, int *connected);</code></pre>
      <pre class="doc-comment">/**
 * Create a new TLS client-side session.
 *
 * Internal function.
 *
 * @param coap_session The CoAP session.
 * @param connected Updated with whether the connection is connected yet or not.
 *                  @c 0 is not connected, @c 1 is connected.
 *
 * @return Opaque handle to underlying TLS library object containing security
 *         parameters for the session.
*/</pre>

      <h4 id="coap_tls_new_server_session">Func <span>coap_tls_new_server_session</span></h4>
      <pre class="doc-declare"><code>void *coap_tls_new_server_session(coap_session_t *coap_session, int *connected);</code></pre>
      <pre class="doc-comment">/**
 * Create a TLS new server-side session.
 *
 * Internal function.
 *
 * @param coap_session The CoAP session.
 * @param connected Updated with whether the connection is connected yet or not.
 *                  @c 0 is not connected, @c 1 is connected.
 *
 * @return Opaque handle to underlying TLS library object containing security
 *         parameters for the session.
 */</pre>

      <h4 id="coap_tls_free_session">Func <span>coap_tls_free_session</span></h4>
      <pre class="doc-declare"><code>void coap_tls_free_session( coap_session_t *coap_session );</code></pre>
      <pre class="doc-comment">/**
 * Terminates the TLS session (may send an ALERT if necessary) then frees the
 * underlying TLS library object containing security parameters for the session.
 *
 * Internal function.
 *
 * @param coap_session The CoAP session.
 */</pre>

      <h4 id="coap_tls_write">Func <span>coap_tls_write</span></h4>
      <pre class="doc-declare"><code>ssize_t coap_tls_write(coap_session_t *coap_session,
                      const uint8_t *data,
                      size_t data_len
                      );</code></pre>
      <pre class="doc-comment">/**
 * Send data to a TLS peer, with implicit flush.
 *
 * Internal function.
 *
 * @param coap_session The CoAP session.
 * @param data      Pointer to data.
 * @param data_len  Number of bytes to send.
 *
 * @return          @c 0 if this should be retried, @c -1 if there is an error
 *                  or the number of cleartext bytes sent.
 */</pre>

      <h4 id="coap_tls_read">Func <span>coap_tls_read</span></h4>
      <pre class="doc-declare"><code>ssize_t coap_tls_read(coap_session_t *coap_session,
                     uint8_t *data,
                     size_t data_len
                     );</code></pre>
      <pre class="doc-comment">/**
 * Read some data from a TLS peer.
 *
 * Internal function.
 *
 * @param coap_session The CoAP session.
 * @param data      Pointer to data.
 * @param data_len  Maximum number of bytes to read.
 *
 * @return          @c 0 if this should be retried, @c -1 if there is an error
 *                  or the number of cleartext bytes read.
 */</pre>

      <h4 id="coap_dtls_startup">Func <span>coap_dtls_startup</span></h4>
      <pre class="doc-declare"><code>void coap_dtls_startup(void);</code></pre>
      <pre class="doc-comment">/**
 * Initialize the underlying (D)TLS Library layer.
 *
 * Internal function.
 *
 */</pre>

      <h4 id="coap_dtls_set_log_level">Func <span>coap_dtls_set_log_level</span></h4>
      <pre class="doc-declare"><code>void coap_dtls_set_log_level(int level);</code></pre>
      <pre class="doc-comment">/**
 * @ingroup logging
 * Sets the (D)TLS logging level to the specified @p level.
 * Note: coap_log_level() will influence output if at a specified level.
 *
 * @param level The logging level to use - LOG_*
 */</pre>

      <h4 id="coap_dtls_get_log_level">Func <span>coap_dtls_get_log_level</span></h4>
      <pre class="doc-declare"><code>int coap_dtls_get_log_level(void);</code></pre>
      <pre class="doc-comment">/**
 * @ingroup logging
 * Get the current (D)TLS logging.
 *
 * @return The current log level (one of LOG_*).
 */</pre>
      <h3 id="vars">Vars</h3>
      

      <h4 id="coap_tls_version_t">Variable <span>coap_tls_version_t</span></h4>
      <pre class="doc-declare"><code>coap_tls_version_t *coap_get_tls_library_version(void);</code></pre>
      <pre class="doc-comment">/**
 * Determine the type and version of the underlying (D)TLS library.
 *
 * @return The version and type of library libcoap was compiled against.
 */</pre>

      <h4 id="coap_dtls_pki_t">Variable <span>coap_dtls_pki_t</span></h4>
      <pre class="doc-declare"><code>struct coap_dtls_pki_t;</code></pre>
      <pre class="doc-comment"></pre>
      <h3 id="consts">Consts</h3>
      
      <h3 id="types">Types</h3>
      
      <h3 id="typedefs">Typedefs</h3>
      

      <h4 id="coap_tls_version_t;
">Typedef <span>coap_tls_version_t;
</span></h4>
      <pre class="doc-declare"><code>typedef struct coap_tls_version_t {
 uint64_t version; /**< (D)TLS runtime Library Version */
 int type; /**< Library type. One of COAP_TLS_LIBRARY_* */
 uint64_t built_version; /**< (D)TLS Built against Library Version */
} coap_tls_version_t;
</code></pre>
      <pre class="doc-comment">/**
 * The structure used for returning the underlying (D)TLS library
 * information.
 */</pre>

      <h4 id="coap_dtls_security_setup_t">Typedef <span>coap_dtls_security_setup_t</span></h4>
      <pre class="doc-declare"><code>typedef int (*coap_dtls_security_setup_t)(void* tls_session,
                                       struct coap_dtls_pki_t *setup_data);
</code></pre>
      <pre class="doc-comment">/**
 * Additional Security setup handler that can be set up by
 * coap_context_set_pki().
 * Invoked when libcoap has done the validation checks at the TLS level,
 * but the application needs to do some additional checks/changes/updates.
 *
 * @param tls_session The security session definition - e.g. SSL * for OpenSSL.
 *                    NULL if server call-back.
 *                    This will be dependent on the underlying TLS library -
 *                    see coap_get_tls_library_version()
 * @param setup_data A structure containing setup data originally passed into
 *                   coap_context_set_pki() or coap_new_client_session_pki().
 *
 * @return @c 1 if successful, else @c 0.
 */</pre>

      <h4 id="coap_dtls_cn_callback_t">Typedef <span>coap_dtls_cn_callback_t</span></h4>
      <pre class="doc-declare"><code>typedef int (*coap_dtls_cn_callback_t)(const char *cn,
            const uint8_t *asn1_public_cert,
            size_t asn1_length,
            coap_session_t *coap_session,
            unsigned depth,
            int validated,
            void *arg);
</code></pre>
      <pre class="doc-comment">/**
 * CN Validation call-back that can be set up by coap_context_set_pki().
 * Invoked when libcoap has done the validation checks at the TLS level,
 * but the application needs to check that the CN is allowed.
 * CN is the SubjectAltName in the cert, if not present, then the leftmost
 * Common Name (CN) component of the subject name.
 *
 * @param cn  The determined CN from the certificate
 * @param asn1_public_cert  The ASN.1 DER encoded X.509 certificate
 * @param asn1_length  The ASN.1 length
 * @param coap_session  The CoAP session associated with the certificate update
 * @param depth  Depth in cert chain.  If 0, then client cert, else a CA
 * @param validated  TLS layer can find no issues if 1
 * @param arg  The same as was passed into coap_context_set_pki()
 *             in setup_data->cn_call_back_arg
 *
 * @return @c 1 if accepted, else @c 0 if to be rejected.
 */</pre>

      <h4 id="coap_asn1_privatekey_type_t;
">Typedef <span>coap_asn1_privatekey_type_t;
</span></h4>
      <pre class="doc-declare"><code>typedef enum coap_asn1_privatekey_type_t {
 COAP_ASN1_PKEY_NONE,    /**< NONE */
 COAP_ASN1_PKEY_RSA,     /**< RSA type */
 COAP_ASN1_PKEY_RSA2,    /**< RSA2 type */
 COAP_ASN1_PKEY_DSA,     /**< DSA type */
 COAP_ASN1_PKEY_DSA1,    /**< DSA1 type */
 COAP_ASN1_PKEY_DSA2,    /**< DSA2 type */
 COAP_ASN1_PKEY_DSA3,    /**< DSA3 type */
 COAP_ASN1_PKEY_DSA4,    /**< DSA4 type */
 COAP_ASN1_PKEY_DH,      /**< DH type */
 COAP_ASN1_PKEY_DHX,     /**< DHX type */
 COAP_ASN1_PKEY_EC,      /**< EC type */
 COAP_ASN1_PKEY_HMAC,    /**< HMAC type */
 COAP_ASN1_PKEY_CMAC,    /**< CMAC type */
 COAP_ASN1_PKEY_TLS1_PRF, /**< TLS1_PRF type */
 COAP_ASN1_PKEY_HKDF     /**< HKDF type */
} coap_asn1_privatekey_type_t;
</code></pre>
      <pre class="doc-comment">/**
 * The enum used for determining the provided PKI ASN.1 (DER) Private Key
 * formats.
 */</pre>

      <h4 id="coap_pki_key_t;
">Typedef <span>coap_pki_key_t;
</span></h4>
      <pre class="doc-declare"><code>typedef enum coap_pki_key_t {
 COAP_PKI_KEY_PEM = 0,  /**< The PKI key type is PEM */
 COAP_PKI_KEY_ASN1,     /**< The PKI key type is ASN.1 (DER) */
} coap_pki_key_t;
</code></pre>
      <pre class="doc-comment">/**
 * The enum used for determining the PKI key formats.
 */</pre>

      <h4 id="coap_pki_key_pem_t;
">Typedef <span>coap_pki_key_pem_t;
</span></h4>
      <pre class="doc-declare"><code>typedef struct coap_pki_key_pem_t {
 const char *ca_file;      /**< File location of Common CA in PEM format */
 const char *public_cert;  /**< File location of Public Cert in PEM format */
 const char *private_key;  /**< File location of Private Key in PEM format */
} coap_pki_key_pem_t;
</code></pre>
      <pre class="doc-comment">/**
 * The structure that holds the PKI PEM definitions.
 */</pre>

      <h4 id="coap_pki_key_asn1_t;
">Typedef <span>coap_pki_key_asn1_t;
</span></h4>
      <pre class="doc-declare"><code>typedef struct coap_pki_key_asn1_t {
 const uint8_t *ca_cert;    /**< ASN1 (DER) Common CA Cert */
 const uint8_t *public_cert; /**< ASN1 (DER) Public Cert */
 const uint8_t *private_key; /**< ASN1 (DER) Private Key */
 size_t ca_cert_len;        /**< ASN1 CA Cert length */
 size_t public_cert_len;    /**< ASN1 Public Cert length */
 size_t private_key_len;    /**< ASN1 Private Key length */
 coap_asn1_privatekey_type_t private_key_type; /**< Private Key Type */
} coap_pki_key_asn1_t;
</code></pre>
      <pre class="doc-comment">/**
 * The structure that holds the PKI ASN.1 (DER) definitions.
 */</pre>

      <h4 id="key;
">Typedef <span>key;
</span></h4>
      <pre class="doc-declare"><code>typedef struct coap_dtls_key_t {
 coap_pki_key_t key_type;         /**< key format type */
 union {
   coap_pki_key_pem_t pem;        /**< for PEM keys */
   coap_pki_key_asn1_t asn1;      /**< for ASN.1 (DER) keys */
 } key;
</code></pre>
      <pre class="doc-comment">/**
 * The structure that holds the PKI key information.
 */</pre>

      <h4 id="coap_dtls_key_t">Typedef <span>coap_dtls_key_t</span></h4>
      <pre class="doc-declare"><code>typedef coap_dtls_key_t *(*coap_dtls_sni_callback_t)(const char *sni,
            void* arg);
</code></pre>
      <pre class="doc-comment">/**
 * Server Name Indication (SNI) Validation call-back that can be set up by
 * coap_context_set_pki().
 * Invoked if the SNI is not previously seen and prior to sending a certificate
 * set back to the client so that the appropriate certificate set can be used
 * based on the requesting SNI.
 *
 * @param sni  The requested SNI
 * @param arg  The same as was passed into coap_context_set_pki()
 *             in setup_data->sni_call_back_arg
 *
 * @return New set of certificates to use, or @c NULL if SNI is to be rejected.
 */</pre>

      <h4 id="coap_dtls_pki_t;
">Typedef <span>coap_dtls_pki_t;
</span></h4>
      <pre class="doc-declare"><code>typedef struct coap_dtls_pki_t {
 uint8_t version; /** Set to 1 to support this version of the struct */

 /* Options to enable different TLS functionality in libcoap */
 uint8_t verify_peer_cert;       /**< 1 if peer cert is to be verified */
 uint8_t require_peer_cert;      /**< 1 if peer cert is required */
 uint8_t allow_self_signed;      /**< 1 if self signed certs are allowed */
 uint8_t allow_expired_certs;    /**< 1 if expired certs are allowed */
 uint8_t cert_chain_validation;  /**< 1 if to check cert_chain_verify_depth */
 uint8_t cert_chain_verify_depth; /**< recommended depth is 3 */
 uint8_t check_cert_revocation;  /**< 1 if revocation checks wanted */
 uint8_t allow_no_crl;           /**< 1 ignore if CRL not there */
 uint8_t allow_expired_crl;      /**< 1 if expired crl is allowed */
 uint8_t reserved[6];            /**< Reserved - must be set to 0 for
                                        future compatibility */
                                  /* Size of 6 chosen to align to next
                                    * parameter, so if newly defined option
                                    * it can use one of the reserverd slot so
                                    * no need to change
                                    * COAP_DTLS_PKI_SETUP_VERSION and just
                                    * decrement the reserved[] count.
                                    */

 /** CN check call-back function.
   * If not NULL, is called when the TLS connection has passed the configured
   * TLS options above for the application to verify if the CN is valid.
   */
 coap_dtls_cn_callback_t validate_cn_call_back;
 void *cn_call_back_arg; /**< Passed in to the CN call-back function */

 /** SNI check call-back function.
   * If not @p NULL, called if the SNI is not previously seen and prior to
   * sending a certificate set back to the client so that the appropriate
   * certificate set can be used based on the requesting SNI.
   */
 coap_dtls_sni_callback_t validate_sni_call_back;
 void *sni_call_back_arg; /**< Passed in to the sni call-back function */

 /** Additional Security call-back handler that is invoked when libcoap has
   * done the standerd, defined validation checks at the TLS level,
   * If not @p NULL, called from within the TLS Client Hello connection
   * setup.
   */
 coap_dtls_security_setup_t additional_tls_setup_call_back;

 char* client_sni;   /**<  If not NULL, SNI to use in client TLS setup.
                             Owned by the client app and must remain valid
                             during the call to coap_new_client_session_pki() */

 coap_dtls_key_t pki_key; /**< PKI key definition */
} coap_dtls_pki_t;
</code></pre>
      <pre class="doc-comment">/**
 * The structure used for defining the PKI setup data to be used.
 */</pre>

      <h4 id="coap_dtls_role_t;
">Typedef <span>coap_dtls_role_t;
</span></h4>
      <pre class="doc-declare"><code>typedef enum coap_dtls_role_t {
 COAP_DTLS_ROLE_CLIENT, /**< Internal function invoked for client */
 COAP_DTLS_ROLE_SERVER /**< Internal function invoked for server */
} coap_dtls_role_t;
</code></pre>
      <pre class="doc-comment"></pre>
    </div>
  </body>
</html>
            